<template>
  <div class="publicBox" id="upNewbuildCss">

<el-form ref="form" :model="ruleForm"  class="demo-form-inline publicEditFrom" :rules="rules" label-width="160px" label-position="left">

<el-row>
     <div class="pubPageTagP">
               <p>更新管理/新建</p>
     </div>
</el-row>

<el-row>
         <el-form-item label="版本号" prop="version">
                    <el-input v-if="!disabledFlag" class="pubIpt200" v-model="ruleForm.version"  placeholder="请输入新版本号"></el-input>
                    <p v-else>{{ruleForm.version}}</p>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="升级类型" prop="upgradeType">
                    <el-radio v-model="ruleForm.upgradeType"  label="1">强制升级</el-radio>
                     <el-radio v-model="ruleForm.upgradeType" label="0">非强制升级</el-radio>
       </el-form-item>
</el-row>

<el-row>
         <el-form-item label="APK包上传" prop="picRe">
            <publicUpdate 
                 :paramsData="ruleForm" 
                 :disabledFlag='disabledFlag'
                 :hrefUpload="action"
                 @successFn="successFn"
                 :acceptUpload="acceptUpload"
                 :textUpload="textUpload"
                 :fileName="fileName"
                 :listType = "listType"
                 ref="publicUpdate"
                 id='publicUpdate'
                 :fileListPro="fileListPro"
                 :tipMessage="tipMessage"
                 :iconFlag=false>
                 <el-button class="pubBtnBlueL btnTop" type="primary"><span v-if="!disabledFlag" >上传</span>
                 <span v-else>重新上传</span></el-button>
                 </publicUpdate>
       </el-form-item>
</el-row>

<el-row>
<el-form-item label="升级提示" required prop="description">
        <el-input
            type="textarea"
            :rows="4"
            class="pubSerIpt"
            placeholder="请输入内容"
            v-model="ruleForm.description">
        </el-input>
  </el-form-item>
</el-row>

<el-row class="pubSubmitBtn-row">
           <el-form-item>
                         <el-button class="pubBtnGray" type="primary" @click="submitForm">保存</el-button>
                         <el-button class="pubBtnGray" @click="$canCleFn"  type="primary">取消</el-button>
          </el-form-item>
</el-row>


</el-form>
  </div>
</template>

<script>
import publicUpdate from "@/components/public/publicUpImg"
import { RowComp } from 'ag-grid-community';
export default {
  components: {
    publicUpdate
  },
  data() {
    return {
    disabledFlag:false,
    acceptUpload:'application/vnd.android.package-archive',
    textUpload:'上传',
    action:"/v1/flash/versions",
    listType:'text',
    tipMessage:'请上传apk包',
    fileListPro:"",
    fileName:"",
    ruleForm:{
        version:"",
        upgradeType:"1",
        description:"",
        id:null,
    },
    rules: {
          version: [
            {required: true, message: '请输入新版本号', trigger: 'blur' }
          ],
          upgradeType: [
            {required: true, message: '请选择升级类型', trigger: 'blur' }
          ],
          description: [
            {required: true, message: '请输入升级提示', trigger: 'blur' }
          ],
        },
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {


  },
  // 监控data中的数据变化
  watch: {


 },
  methods: {

    submitForm() {
           this.$refs["form"].validate((valid) => {
            if (valid) {
                this.$refs.publicUpdate.submitUpload(this.ruleForm)
            } else {
              return false;
            }
        });
       },
    successFn(res){
               if(res.IsPositive){
                  this.$message.success({message:"操作成功"})
                  this.$router.go(-1)
                }else{
                  this.$message.error({message:res.ErrorCode})
                }
    }
  },
 created() {
 if(this.$route.query.data!=undefined){              //ES6写法, Object.keys(targetObject)  将对象的key作为一个数组返回
            this.disabledFlag=true    
             this.ruleForm.version=this.$route.query.data.version
             this.ruleForm.upgradeType=String(this.$route.query.data.upgradetype)
             this.ruleForm.description=this.$route.query.data.description
             this.fileListPro=this.$route.query.data.url
             this.fileName=this.$route.query.data.name
             this.ruleForm.id=this.$route.query.data.idstr
   }
  },
  mounted() {


  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang="less">
  #publicUpdate{
        .el-upload--picture-card{
        border: none;
        height: 50px;
        line-height: 0px;
        width: 91px;
    }
  }
</style>

<style lang='less'>
#bannerNewbuildCss{
.add_box{
    width:380px;
    height:149px;
    border:1px solid #BBBBBB;
    position: relative;
}
.Listbox{
    display: flex;
    flex-direction: row;
}
}


</style>